<template>
    <div class="warehouse-ownership-page">
        <el-form :inline="true" :model="wareHouseOwnershipForm" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
            <el-form-item label="法人名称" class="selectMB10 label-w1 ">  <!--  v-if="!powerFlag"  -->
                <el-input size="mini" v-if="legalPersonDropDown.length==1" disabled v-model="wareHouseOwnershipForm.legalPersonName" placeholder=""></el-input>
                <el-select size="mini" clearable v-else  v-model="wareHouseOwnershipForm.legalPersonId" placeholder="请选择">
                    <el-option v-for="(legalPerson,index) in legalPersonDropDown" :key="index" :label="legalPerson.legalPersonName" :value="legalPerson.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="库房编码" class="selectMB10 label-w1 ">
                <el-input size="mini" v-model="wareHouseOwnershipForm.code" placeholder="请输入库房"></el-input>
            </el-form-item>
            <el-form-item label="库房名称" class="selectMB10 label-w1 ">
                <el-input size="mini" v-model="wareHouseOwnershipForm.name" placeholder="请输入库房名称"></el-input>
            </el-form-item>
            <el-form-item label="库房描述" class="selectMB10 label-w1 ">
                <el-input size="mini" v-model="wareHouseOwnershipForm.remark" placeholder="请输入库房名称"></el-input>
            </el-form-item>
             <el-form-item label="当前状态" class="selectMB10 label-w1 " style="margin-right: 10px;">
                <el-select size="mini" clearable v-model="wareHouseOwnershipForm.status" placeholder="请选择">
                    <el-option v-for="(status,index) in statusLists" :key="index" :label="status.lable" :value="status.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item class="selectMB10">
                <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="queryWarehouse()">查询</el-button>
            </el-form-item>
        </el-form>
        <!--表格-->
        <label class="default-label">库房列表：</label>
        <!--新增按钮-->
        <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="handleCreate()">新增</el-button>
        <el-table :data="wareHouseData" border style="width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
            <el-table-column label="操作" header-align="center" align="center" width="120">
                <template scope="scope">
                    <div class="operationItem bolder" v-if="scope.row.status" @click="handleStatus(scope.$index,scope.row)">禁用</div>
                    <div class="operationItem bolder" v-else @click="handleStatus(scope.$index,scope.row)">启用</div> 
                    <div class="operationItem disabled bolder" v-if="scope.row.status || scope.row.manageProperty != 10">修改</div>
                    <div class="operationItem bolder" v-else @click="handleUpdate(scope.$index,scope.row)">修改</div>
                    <div class="operationItem bolder" @click="handleSee(scope.$index,scope.row)">查看</div>
                </template>
            </el-table-column>
            <el-table-column prop="code" label="库房编码" header-align="center" width="100" show-overflow-tooltip></el-table-column>
            <el-table-column prop="name" label="库房名称" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="remark" label="库房描述" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="storageSectionCode" label="库区编码" header-align="center" width="100" show-overflow-tooltip></el-table-column>
            <el-table-column prop="storageSectionName" label="库区名称" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="storageSectionRemark" label="库区描述" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="statusName" label="状态" header-align="center" align="center" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column prop="legalPersonName" label="法人名称" header-align="center" show-overflow-tooltip></el-table-column>
        </el-table>
        <!--分页-->
        <el-pagination v-if="isPaging" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageIndex"  :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="totalPage" :total="totalNumber"></el-pagination>
    </div>
</template>
<script>
       export default {
        data() {
            return {
                // 查询表单
                wareHouseOwnershipForm:{
                    legalPersonId:"",
                    legalPersonName:"",
                    name:"",
                    code:"",
                    status:"",
                    remark:""
                },
                legalPersonDropDown:[],  // 法人名称下拉列表
                statusLists:[],   //当前状态下拉列表
                wareHouseData:[],
                loading:false,
                disabled:false,
                // 分页
                isPaging:false,
                pageIndex:1,    //当前页（必传）
                pageSize :10,   //每页多少条
                totalNumber: 20,
                totalPage:2,
                
                //查询禁用
                selectDisabled:false
            };
        },
       //进入页面立即运行此方法
       mounted: function () {
            var _this = this;
            _this.$store.commit('currentActive', 'WarehouseOwnership');
            // //ajax前后查询按钮禁用
            // $(".selectAll").ajaxStart(function(){
            //     _this.selectDisabled=true;
            // });
            // $(".selectAll").ajaxStop(function(){
            //     _this.selectDisabled=false;
            // });
            _this.legalPersonDropDownValue(); //法人名称下拉列表值
            _this.dropDownValue();// 当前状态下拉列表
       },
        methods:{
            //法人名称下拉列表值
            legalPersonDropDownValue(){  
                var _this = this;
                $.ajax({
                    type:'GET',
                    url:_this.procurement_service+"legalPerson/ofCurrentUser",
                    cache:false,
                    success:function(data){
                        if(data.success){
                            _this.legalPersonDropDown = data.data;
                            if(_this.legalPersonDropDown.length == 1){
                                _this.wareHouseOwnershipForm.legalPersonId = _this.legalPersonDropDown[0].id;
                                _this.wareHouseOwnershipForm.legalPersonName = _this.legalPersonDropDown[0].legalPersonName;
                            }
                            _this.queryWarehouse();    //表单查询
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            // 当前状态下来列表
            dropDownValue(){
                var _this=this;
                var tmp=["pickingArea.pickingAreaStatus"];
                $.ajax({
                    type:'POST',
                    url:_this.iwm_service+'stock/getPullDownList',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:"application/json;charset=utf-8",
                    success:function(data){
                        if(data.success){
                            _this.statusLists=data.data;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            //查询库房列表
            queryWarehouse(){
                var _this=this;
                _this.loading=true;
                var tmp={
                    legalPersonId:_this.wareHouseOwnershipForm.legalPersonId,
                    name:_this.wareHouseOwnershipForm.name,
                    code:_this.wareHouseOwnershipForm.code,
                    remark:_this.wareHouseOwnershipForm.remark,
                    status:_this.wareHouseOwnershipForm.status,
                    pageIndex:_this.pageIndex,
                    pageSize:_this.pageSize
                };
                _this.selectDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.iwm_service+"ship/queryPage",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            _this.loading=false;
                            _this.isPaging=true;
                            _this.totalPage=data.data.totalPage;
                            _this.totalNumber=data.data.totalNumber;
                            _this.wareHouseData=data.data.dataList;
                        }else{
                            _this.common.errorTip(data.errorMessage)
                        }
                        _this.selectDisabled=false;
                    }
                });
            },
            //新增库房信息
            handleCreate(){
                var _this=this;
                _this.$router.push("/CreateWarehouseOwnership");
            },
            // 操作启用禁用
            handleStatus(index, row){
                var _this=this;
                if(row.status){
                    row.status = false;
                }else{
                    row.status = true;
                }
                var tmp={id: row.id,status: row.status}; 
                $.ajax({
                    type: 'POST',
                    url: _this.iwm_service+"CompanyStorage/updateStatus",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            // 当前状态的显示
                            if(row.status){
                                row.statusName = "启用";
                                _this.common.successTip("启用成功！");
                            }else{
                                row.statusName = "禁用";
                                _this.common.successTip("禁用成功！");
                            }
                        }else
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            //点击修改
            handleUpdate(index,row){
                var _this=this;
                _this.$router.push({path:"/UpdateWarehouseOwnership",query:{id:row.id}});
            },
            // 点击查看
            handleSee(index,row){
                var _this=this;
                _this.$router.push({path:"/SeeWarehouseOwnership",query:{id:row.id}});
            },
            //   分页
            handleSizeChange(val) {
                var _this=this;
                _this.pageSize=val;
                _this.queryWarehouse();

            },
            //点击页码分页查询点击事件
            handleCurrentChange(val) {
                var _this=this;
                _this.pageIndex=val;
                _this.queryWarehouse();
            },
            // // ===================================
            // successTip(p) {     //成功时的提示信息
            //     this.$notify({
            //         title: '成功',
            //         message: p,
            //         type: 'success'
            //     });
            // },
            // errorTip(p) {     //错误提示
            //     this.$notify.error({
            //         title: '错误',
            //         message: p
            //     });
            // }

        }
    }
</script>
